/** 
Copyright (c) 2010, Sheikh Abdul Wahid Ahmed
Details @ http://extremecodeworld.codeplex.com/license
**/

using System;
using System.Collections;
using System.Data;
using System.Xml;
using EXtremecode.Utils;
namespace EXtremecode.EntityDefinition
{
	/// <summary>
	/// Summary description for EntityField.
	/// </summary>
	public abstract class EntityField
	{
		protected string m_strEntityFieldName;
		protected string m_strDataType;
		protected Entity m_entityOwner;
		public EntityField(string name,string dataType,Entity entityOwner)
		{
			m_strEntityFieldName=name;
			m_strDataType=dataType;  
			m_entityOwner=entityOwner;
		}
		public virtual XmlElement BuildXml(XmlDocument ownerDocument)
		{
			XmlElement element= ownerDocument.CreateElement(XMLSpecific.PREFIX,"field",XMLSpecific.XMLN);
			XmlAttribute atb;

			//----name---
			atb= ownerDocument.CreateAttribute("name");
			atb.InnerText=m_strEntityFieldName;
			element.Attributes.Append(atb);

			/*

			//----property---
			atb= ownerDocument.CreateAttribute("property");
			atb.InnerText=StringProcessor.Property(m_strEntityFieldName);
			element.Attributes.Append(atb);

			//----caption---
			atb= ownerDocument.CreateAttribute("caption");
			atb.InnerText=StringProcessor.Caption(m_strEntityFieldName);
			element.Attributes.Append(atb);
			
			*/

			//----datatype---
			atb= ownerDocument.CreateAttribute("datatype");
			atb.InnerText= m_strDataType;
			element.Attributes.Append(atb);

			return element;

			
		}

		public string Name
		{
			get
			{
				return m_strEntityFieldName; 
			}
		}
		public Entity Entity
		{
			get
			{
				return m_entityOwner; 
			}
		}
	}
	public class EntityFieldCollection:Hashtable
	{
		
		
		
		public EntityField this[string key]
		{
			get
			{
				return (base[key] as EntityField);
			}
			
		}
		public  void Add(string key, EntityField value)
		{
			if(base.Contains(key))throw new Exception(string.Format("[UE] Entity Field with the key '{0}', already exsists",key));
			base.Add(key,value);
		}
		
		
		#region Hidden Methods
		public override void Add(object key, object value)
		{
			throw new Exception("[UE] method is not allowed");
		}
		public override void CopyTo(Array array, int arrayIndex)
		{
			throw new Exception("[UE] method is not allowed");

		}
		#endregion
	}
}
